<template>
  <view class="commonLim-list">
    <!-- 表单内容 -->
    <view class="form-content flexandauto">
      <view class="form-item">
        <view>
          <text class="label">退库编号:</text>
        </view>
        <view>
          <text v-if="profile.returnNo" class="iptClass">{{
            profile.returnNo
          }}</text>
          <text class="dianwo" v-else>编号自动生成</text>
        </view>
      </view>
      <view class="form-item">
        <text class="label" style="color: red">*</text>
        <text class="label">退库原因:</text>
        <input
          class="iptClass textright"
          placeholder="请输入备 注"
          v-model.trim="profile.returnReason"
          style="width: 100%"
        />
      </view>
      <view class="form-item">
        <text class="label">备 注:</text>
        <input
          class="iptClass textright"
          placeholder="请输入备 注"
          v-model.trim="profile.remark"
          style="width: 100%"
        />
      </view>
      <view class="form-item" style="align-items: center">
        <text class="label" style="margin-right: auto">退库原料 </text>
        <view style="display: flex">
          <button class="cancelClass" @click="choose">选择</button>
          <button class="cancelClass" @click="qingkong">清空</button>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label" style="color: red">*</text>
          <text class="label">原料编码:</text>
        </view>
        <view>
          <text v-if="profile.rawMaterialCode" class="iptClass">{{
            profile.rawMaterialCode
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">材质:</text>
        </view>
        <view>
          <text v-if="profile.materialTypeName" class="iptClass">{{
            profile.materialTypeName
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">规格型号:</text>
        </view>
        <view>
          <text v-if="profile.specificationName" class="iptClass">{{
            profile.specificationName
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">炉号:</text>
        </view>
        <view>
          <text v-if="profile.heatNo" class="iptClass">{{
            profile.heatNo
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">领取数量:</text>
        </view>
        <view>
          <text v-if="profile.receiveQuantity" class="iptClass">{{
            profile.receiveQuantity
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">厂商:</text>
        </view>
        <view>
          <text v-if="profile.supplierName" class="iptClass">{{
            profile.supplierName
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">卷号:</text>
        </view>
        <view>
          <text v-if="profile.coilNo" class="iptClass">{{
            profile.coilNo
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">领料编号:</text>
        </view>
        <view>
          <text v-if="profile.pickNo" class="iptClass">{{
            profile.pickNo
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">退库数量:</text>
        </view>
        <view>
          <text v-if="profile.returnQuantity" class="iptClass">{{
            profile.returnQuantity
          }}</text>
          <text class="dianwo" v-else>自动带出</text>
        </view>
      </view>
    </view>
    <!-- 提交按钮 -->
    <view class="dengjiClass">
      <button @click="onSubmit" class="commonClass">提 交</button>
    </view>
  </view>
</template>

<script setup>
import { materialReturnSumit } from "./api.js";
import { useMemberStore } from "@/stores/modules/member";
const memberStore = useMemberStore();
const deprops = defineProps(["title"]);
const profile = ref({});
const choose = () => {
  uni.navigateTo({
    url: `/pages/ReturnToTnventory/ReturnToTnventory`,
  });
};
const qingkong = () => {
  profile.value.rawMaterialCode = "";
  profile.value.materialTypeName = "";
  profile.value.specificationName = "";
  profile.value.heatNo = "";
  profile.value.receiveQuantity = "";
  profile.value.supplierName = "";
  profile.value.coilNo = "";
  profile.value.pickNo = "";
  profile.value.returnQuantity = "";
};
// 点击提交表单
const onSubmit = async () => {
  try {
    if (!profile.value.returnReason) {
      return uni.showToast({
        icon: "none",
        title: "退库原因不能为空",
      });
    }
    if (!profile.value.rawMaterialCode) {
      return uni.showToast({
        icon: "none",
        title: "原料编码不能为空",
      });
    }
    uni.showLoading({
      title: "加载中",
    });
    profile.value.createBy = memberStore.userId;
    profile.value.orderById = memberStore.userId;
    profile.value.orderByName = memberStore.userName;
    await materialReturnSumit({
      order: profile.value,
      suggestion: "同意",
    });
    uni.showToast({ icon: "success", title: "操作成功" });
    uni.navigateBack({ delta: 1 });
  } finally {
    uni.hideLoading();
  }
};
onLoad(async () => {
  uni.setNavigationBarTitle({
    title: deprops.title,
  });
  memberStore.stateTable.rows = [];
  if (deprops.title == "新增退库") {
    profile.value = {};
  } else {
    profile.value = memberStore.currenttukutable;
  }
});
//领料人
onShow(() => {
  const obj = memberStore.stateTable.rows[0];
  if (obj) {
    profile.value.rawMaterialId = obj.id;
    profile.value.rawMaterialCode = obj.rawMaterialCode;
    profile.value.materialTypeId = obj.materialTypeId;
    profile.value.materialTypeName = obj.materialTypeName;
    profile.value.specificationId = obj.specificationId;
    profile.value.specificationName = obj.specificationName;
    profile.value.heatNo = obj.heatNo;
    profile.value.receiveQuantity = obj.remainingQuantity;
    profile.value.returnQuantity = obj.remainingQuantity;
    profile.value.supplierName = obj.supplierName;
    profile.value.coilNo = obj.coilNo;
    profile.value.pickNo = obj.pickNo;
    profile.value.unit = obj.unit;
  }
  memberStore.stateTable.rows = [];
});
</script>

<style lang="scss" scoped>
</style>
